
const  userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
const  token = localStorage.getItem('token')
let state = {
  userInfo: userInfo,
  token: token
}

const getters = {
  userInfo(state) {
    let result = JSON.parse(localStorage.getItem('userInfo') || '{}')
    if (result) {
      state.userInfo = result
    }
    return state.userInfo;
  },
  getToken(state) {
    let result = localStorage.getItem('token')
    if (result) {
      state.token = result
    }
    return state.token;
  },
}

const mutations = {
  saveUser(state, data) {
    state.userInfo = data;
    localStorage.setItem('userInfo',JSON.stringify(state.userInfo))
  },
  saveToken(state, data) {
    state.token = data;
    localStorage.setItem('token',state.token)
  },
  updateUserInfo(state, data) {
    state.userInfo.haedPic = data;
    localStorage.setItem('userInfo',JSON.stringify(state.userInfo))
  },

}

export default {
  state,
  getters,
  mutations
}